function [ seg_pic ] = multi_partition( edge_map, score_trashold, penalty_vec, depth )
%MULTI_PARTITION Summary of this function goes here
%   Detailed explanation goes here

    edge_map = double(edge_map);

    % intializing input sizes
    def_depth = 3;
    if nargin < 2 
        score_trashold =0.3;
        penalty_vec = [0,0.1,0.1,0.1,0];
        depth = def_depth;
    elseif nargin <3
        penalty_vec = [0,0.1,0.1,0.1,0];
        depth = def_depth;
    elseif nargin < 4
        depth = def_depth;
    end

    [N,M] = size(edge_map);
    seg_pic = zeros([N,M]);

    [split_img_main,score] = partition(edge_map,penalty_vec);
%     score
    
    if score > score_trashold
        if depth == 1
            seg_pic = split_img_main;
            return 
        end
        
            
        % lower
        new_edge = edge_map;
       for j = 1:M
            i = find(split_img_main(:,j));
            new_edge(1:i,j) = -M*N;
            if (i+1) <= N
                new_edge(i+1,j) = 0;
            end
            if (i+2) <= N
                new_edge(i+2,j) = 0;
            end
       end
        split_img_bottom = multi_partition(new_edge,score_trashold,penalty_vec, depth-1);
        
        %upper
        new_edge = edge_map;
        for j = 1:M
            i = find(split_img_main(:,j));
            new_edge(max(1,i):N,j) = -M*N;
            if i-1 >= 1
                new_edge(i-1,j) = 0;
            end
        end
        split_img_top = multi_partition(new_edge,score_trashold,penalty_vec, depth-1);
        
        seg_pic = split_img_top+split_img_main+split_img_bottom;
    end
    
end
